﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Motorbike.Model;

namespace Motorbike.APP.Forms
{
    public partial class MainApplicationForm : AbsBaseForm
    {
        public MainApplicationForm()
        {
            InitializeComponent();
        }

        private void MainApplicationForm_Load(object sender, EventArgs e)
        {
            CheckUserLogin();
            this.FormClosing+=new FormClosingEventHandler(MainApplicationForm_FormClosing);
        }

        protected void MainApplicationForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (Confirm("你确定要退出系统吗！？") != System.Windows.Forms.DialogResult.Yes)
            {
                e.Cancel = true;
            }
        }

        private void CheckUserLogin()
        {
            if (null == ApplicationContext.Instance.CurrentUser)
            {
                ShowWarning("系统没有你的登录信息，请先登录......");
                this.Close();

                LoginForm loginForm = new LoginForm();
                loginForm.ShowDialog();
            }

            LoginLog loginLog = ApplicationContext.Instance.CurrentLoginLog;
            welcomeLabel.Values.ExtraText = "登录时间：" + loginLog.LoginTime + "\t本机地址：" + loginLog.HostAddress;

            welcomeLabel.Text = "欢迎您使用本系统：" + ApplicationContext.Instance.CurrentUser.Name
                + " (" + ApplicationContext.Instance.CurrentUser.Code + ")";
        }

        private void toolQuit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
